var Adusers=function(){
	var grid;
	var fs,win,pageSize=20;
	var stationmasterfrom=new Ext.FormPanel({
							labelWidth: 75, // label settings here cascade unless overridden
							url:'./?ctrl=adusers&action=insert',
							frame:true,
							title: '信息',
							bodyStyle:'padding:0px 0px 0',
							layout:'form',
							width:"100%",
							defaults: {width: 230},
							defaultType: 'textfield',
							items: [{
								fieldLabel: '用戶名',
								name: 'aduser[username]',
								allowBlank:false
							},{
								fieldLabel: '密 碼',
								name: 'aduser[password]',
								inputType : 'password',
								allowBlank:false
							},new Ext.ux.Multiselect({
									name:"aduser[ptypes]",
									fieldLabel:  '可查看廣告',
									dataFields:  ['id', 'title'], 
									data:  ptypeList,
									valueField:  'id',
									displayField:  'title',
									width:  150,
									height:  150,
									allowBlank:false
								})
							],
							buttons: [{
								text: '提交',
								handler :function(e){
									stationmasterfrom.getForm().submit({
										waitMsg:"提交中",
										failure:function (form,action){Ext.MessageBox.alert("信息","提交失败！");},
										success :function (form,action){
											Ext.MessageBox.alert("信息","提交成功");
											grid.store.reload();
											win.hide();
										}
									});
								},
								scope :this
							},{
								text: '取消',
								handler :function(e){win.hide();}
							}]
						}); 
	win=new Ext.Window({
		title: '編輯用戶',
		layout:'fit',
		width:420,
		height:400,
		closeAction:'hide',
		plain: true,
		items: [stationmasterfrom]
	}); 
	var ds=new Ext.data.Store({
		proxy:new Ext.data.HttpProxy({url:'./?ctrl=adusers&action=get'}),
		reader:new Ext.data.JsonReader({
			root: 'topics',
			totalProperty: 'totalCount',
			id: 'id',
			fields: ['id','username']
		})
	});
	var buildGrid = function(){
		grid = new Ext.grid.GridPanel({
			store:ds,
			columns:[
			new Ext.grid.RowNumberer({header :'ID',dataIndex:'id'}),
			{header:'用戶名',width:550,sortable:true,dataIndex:'username',editor:new Ext.form.TextField()}
			],bbar:new Ext.PagingToolbar({
				pageSize:pageSize,
				store:ds,
				displayInfo:true
			}),
			viewConfig:{
				forceFit:true
			},
			renderTo:'grid',
			height: 415,
			border:false
		});
		grid.on('cellclick',function(g,rowIndex,columnIndex,e){
			var url="./?ctrl=adusers&action=form&id="+g.selModel.selections.items[0].data.id;
			var f_dom=Ext.get('safe').dom;
			if(f_dom.src!=url){
				f_dom.src=url;
			}
		});
		grid.store.load();
	};
	var buildLayout = function(){
		var toolbar = new Ext.Panel({
			border:false,
			tbar:[{
					text:'添加',
					cls:'x-btn-text-icon',
					icon:RES_ROOT_PATH+'images/add.gif',
					handler:function(){
						win.show();
					}
				}]
		});

		var layout = new Ext.Viewport({
			layout:'border',
			defaults:{border:false},
			items:[{
				region:'north',
				title:'廣告主管理',
				height:52,
				items:toolbar
			},{
				region:'west',
				width:580,
				height: 200,
				split:true,
				autoScroll:true,
				items:grid
			},{
				region:'center',
				layout:'fit',
				title:'浏览区',
				items:new Ext.Panel({
					renderTo:"panl",
					html : Ext.isIE?'<iframe id="safe" scrolling="no" frameborder="0" style="width:100%;height:100%;"></iframe>':'<iframe id="safe" scrolling="no" frameborder="0" style="width:100%;height:800px;"></iframe>'
				})
			}]
		});
	}
	return{
		init:function(){
			buildGrid();
			buildLayout();
		}
	}
}();
Ext.onReady(Adusers.init,Adusers);